package com.apes.framework.plugin.esb.processor.connector.http;

import com.alibaba.fastjson.JSONObject;
import com.apes.framework.plugin.esb.processor.connector.Transporter;
import com.apes.framework.util.Tools;
import lombok.Data;

import java.util.Map;

/**
 * 功能：Http传输器类
 *
 * @author xul
 * @create 2017-12-05 20:04
 */
@Data
public class HttpTransporter extends Transporter {

    private String url;
    private String header = null;
    private String responseType;  // 返回解析类型
    private String action = "POST";
    private Boolean returnHeaders = false;

    public HttpTransporter() {
        super();
        setConnector(new HttpClient4Connector());
    }

    public void setUrl(String url) {
        this.url = url;
        ((HttpClient4Connector) this.getConnector()).setUrl(url);
    }

    public Map<String, String> getHeaders() {
        return ((HttpClient4Connector) this.getConnector()).getHeaders();
    }

    public void setHeader(String headers) {
        this.header = headers;
        if (Tools.isNull(this.header)) {
            return;
        }
        ((HttpClient4Connector) this.getConnector()).setHeaders(JSONObject.parseObject(this.header));
    }

    public void setHeaders(Map<String, String> headers){
        ((HttpClient4Connector) this.getConnector()).setHeaders(headers);
    }

    public void setResponseType(String responseType) {
        this.responseType = responseType;
        ((HttpClient4Connector) this.getConnector()).setResponseType(responseType);
    }

    public void setAction(String action) {
        this.action = action;
        ((HttpClient4Connector) this.getConnector()).setAction(action);
    }

    public void setReturnHeaders(Boolean returnHeaders) {
        this.returnHeaders = returnHeaders;
        ((HttpClient4Connector) this.getConnector()).setReturnHeaders(returnHeaders);
    }
}
